package top.lixunda.ecommerce.server.good.api.entity.vo;

import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import org.springframework.beans.BeanUtils;
import top.lixunda.common.utils.ObjectValidators;
import top.lixunda.ecommerce.server.good.api.entity.db.GoodPictureDO;

import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * @author Xumda
 * @version time:2020/1/15 15:25
 */
@SuppressWarnings("WeakerAccess")
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
public class GoodPictureVO {

    /**
     * 商品图片Id，自动增长
     */
    private Integer id;

    /**
     * 商品id
     */
    private Integer goodId;

    /**
     * 商品名称
     */
    private String goodName;

    /**
     * 大图片
     */
    private String largeImage;

    /**
     * 中等图片
     */
    private String middleImage;

    /**
     * 缩略图
     */
    private String smallImage;

    /**
     * 图片排序，小数在前，用于设置轮播图顺序，相同时排序不定
     */
    private Integer order;

    /**
     * 备注信息
     */
    private String remark;

    /**
     * 转换
     *
     * @param goodPictureDO goodPictureDO
     * @return GoodPictureVO
     */
    public static GoodPictureVO fromGoodPictureDO(GoodPictureDO goodPictureDO) {
        if (ObjectValidators.isEmpty(goodPictureDO)) {
            return null;
        }
        GoodPictureVO goodPictureVO = new GoodPictureVO();
        BeanUtils.copyProperties(goodPictureDO, goodPictureVO);
        return goodPictureVO;
    }

    /**
     * 转换
     *
     * @param list List<GoodPictureDO>
     * @return List<GoodPictureVO>
     */
    public static List<GoodPictureVO> fromGoodPictureDO(List<GoodPictureDO> list) {
        if (list == null) {
            return null;
        }
        return list.stream()
                .map(GoodPictureVO::fromGoodPictureDO)
                .filter(Objects::nonNull)
                .collect(Collectors.toList());
    }

}
